/*
 * @Author: xiaoliang
 * @Date: 2025-03-05 14:46:02
 * @LastEditors: xiaoliang
 * @LastEditTime: 2025-03-05 14:46:04
 * @FilePath: /codepiece/shuffleArray.js
 * @Description: 洗牌算法
 */

function shuffleArray(arr) {
  for (let i = arr.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [arr[i], arr[j]] = [arr[j], arr[i]]; // 交换元素
  }
  return arr;
}

const orderedArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const shuffledArray = shuffleArray(orderedArray);
console.log(shuffledArray); // 输出打乱后的数组